//
//  ReSetPasswordTwoViewController.m
//  SIPphone
//
//  Created by wrt on 15-2-5.
//  Copyright (c) 2015年 wrtsoft. All rights reserved.
//

#import "ReSetPasswordTwoViewController.h"
#import "ReSetPasswordThreeViewController.h"
#import "SVProgressHUD.h"

@interface ReSetPasswordTwoViewController ()
{
    int codeCount;
}
@end

@implementation ReSetPasswordTwoViewController

- (id)initWithUserName:(NSString *)userName
{
    self = [super init];
    if (self)
    {
        self.username = [[NSString alloc] init];
        self.username = userName;
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[NetPostClass shareNetPostClass] setDelegate:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    //判断版本号 然后选择相应的ui界面
    float systemVersion = iOSValue;
    if (systemVersion >= 7.0)
    {
        self.edgesForExtendedLayout=UIRectEdgeNone;
    }
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.title = NSLocalizedString(@"password Reset", @"密码重置 Password Reset");
    
    [self.reGetCheckCodeButton setTitle:self.username forState:UIControlStateNormal];
    [self.reGetCheckCodeButton setUserInteractionEnabled:NO];
    
    codeCount = 120;
    self.codeTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeCodeTime) userInfo:nil repeats:YES];
    
}

- (void)changeCodeTime
{
    codeCount--;
    if (codeCount < 1)
    {
        [self.reGetCheckCodeButton setUserInteractionEnabled:YES];
        [self.codeTimer invalidate];
        self.timeLabel.text = @"120";
        return;
    }
    self.timeLabel.text = [NSString stringWithFormat:@"%d",codeCount];
}

- (IBAction)reGetCheckCodeButtonPressed:(id)sender
{
    [[NetPostClass shareNetPostClass] postGetCheckCodeWithUserName:self.username];
    
    codeCount = 120;
    self.codeTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeCodeTime) userInfo:nil repeats:YES];
}

- (IBAction)nextbuttonPressed:(id)sender
{
    ReSetPasswordThreeViewController *reSetThreeVC = [[ReSetPasswordThreeViewController alloc] initWithUserName:self.username];
    [self.navigationController pushViewController:reSetThreeVC animated:YES];
}

#pragma NetPostDelegateMethod
/**
 *  post数据成功回调
 *
 *  @param comeBackDic 返回来的字典数据
 *  @param tagNumber   post的tag标识
 */
- (void)postSuccessfulWithString:(NSDictionary *)comeBackDic withTag:(int)tagNumber
{
    [SVProgressHUD showSuccessWithStatus:NSLocalizedString(@"sent successfully", @"发送成功 Sent successfully")];
}
/**
 *  post失败返回数据
 *
 *  @param faileString 失败的原因
 *  @param tagNumber   post的tag标识
 */
- (void)postFailedWithString:(NSString *)faileString withTag:(int)tagNumber
{
    //post失败返回的失败原因
    [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"failed to send", @"发送失败 Failed to send")];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
